package fiuba.algo3.algoThieft.vista;

import java.awt.Button;
import java.awt.Dialog;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

@SuppressWarnings("serial")
public class DialogMensaje extends Dialog implements ActionListener {
	
	private Button BotonAceptar = new Button("Aceptar");
	
	
	public DialogMensaje(Frame owner, String title, String mensaje) {
		
		super(owner, mensaje , true);
		
		
		this.setTitle(title);
		
		setLayout(new GridLayout(0, 1));
		setFont(new Font("Helvetica", Font.PLAIN, 12));
		FontMetrics fm = this.getFontMetrics(getFont());
		
		int ancho = 50 + fm.stringWidth(mensaje);

		setSize(ancho, 125); 
		setResizable(false);
		
		new CentralizadorDeVentana().centrarVentana(this);

		
		Label lblMsg = new Label(mensaje);
		lblMsg.setAlignment(Label.CENTER);
		this.add( "Center" , lblMsg);
		Panel panelBotones = new Panel();
		panelBotones.add(BotonAceptar);
		
		this.add( "South" , panelBotones);
					
		this.BotonAceptar.addActionListener(this);
		
		this.setVisible(true);
		
		
	}
	
	public DialogMensaje(Frame frame, String title, String linea1,
			String linea2) {
		super(frame, linea1 , true);
		
		
		this.setTitle(title);
		
		setLayout(new GridLayout(0, 1));
		setFont(new Font("Helvetica", Font.PLAIN, 12));
		FontMetrics fm = this.getFontMetrics(getFont());
		
		int ancho1 = 50 + fm.stringWidth(linea1);
		int ancho2 = 50 + fm.stringWidth(linea2);
		int ancho = Math.max(ancho1, ancho2);

		setSize(ancho, 125); 
		setResizable(false);

		new CentralizadorDeVentana().centrarVentana(this);

		
		Label lblMsg1 = new Label(linea1);
		Label lblMsg2 = new Label(linea2);
		Panel panelLabel = new Panel();
		panelLabel.add(lblMsg1);
		panelLabel.add(lblMsg2);
		Panel panelBotones = new Panel();
		panelBotones.add(BotonAceptar);
		
		this.add( "Center" , panelLabel);
		this.add( "South" , panelBotones);
					
		this.BotonAceptar.addActionListener(this);
		
		this.setVisible(true);
	}

	public static class CloseListener extends WindowAdapter	
	{	public void windowClosing(WindowEvent e)
	{	
		e.getWindow().dispose();
	}
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		this.dispose();
		
	}


}
